A Pythagorean triplet is a set of three natural numbers, a < b < c, for which, a2 + b2 = c**2

For example, 32 + 42 = 9 + 16 = 25 = 5**2.

There exists exactly one Pythagorean triplet for which a + b + c = 1000. Find the product abc.


In [8]:
def find
  (1..997).each do |i|
    (i+1..998).each do |j|
      k = 1000 - i - j
      return i * j * k if ((i**2 + j**2) == k**2)
    end
  end
end

find


Out[8]:
31875000

In [ ]: